package com.dzt.androidframework.photo;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;
import com.dzt.androidframework.photo.adapter.ImageRecycleViewAdapter;
import com.dzt.androidframework.photo.adapter.PicassoRecycleViewAdapter;
import com.dzt.androidframework.utils.JLogKit;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.recyclerview.adapters.ScaleInAnimationAdapter;
import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator;

public class PicassoActivity extends ActivityTitle {

	@ViewInject(R.id.recyclerview)
	private RecyclerView recyclerView;
	private PicassoRecycleViewAdapter adapter;
	private LinearLayoutManager layoutManager;
	private List<UrlImage> datas = new ArrayList<>();

	@Override
	protected int getLayoutId() {
		return R.layout.activity_picasso;
	}

	@Override
	protected void initParams() {
		setTitleView(R.string.text_picasso);
		String urls[] = getResources().getStringArray(R.array.urls);
		String names[] = getResources().getStringArray(R.array.names);
		for (int i = 0; i < urls.length; i++) {
			UrlImage image = new UrlImage();
			image.url = urls[i];
			image.name = names[i];
			datas.add(image);
		}

		adapter = new PicassoRecycleViewAdapter(this, datas, R.layout.item_car);
		layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
		recyclerView.setLayoutManager(layoutManager);
		recyclerView.setItemAnimator(new SlideInLeftAnimator());
		recyclerView.setAdapter(new ScaleInAnimationAdapter(adapter));
		adapter.setOnItemClickListener(new onItemClickListener());
	}

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	public class onItemClickListener implements ImageRecycleViewAdapter.OnItemClickListener {
		@Override
		public void onItemClick(View view, int position) {
			JLogKit.getInstance().e("onItemClick pos = " + position);
		}
	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}
}
